package hot100;

public class rotate2 {
    class Solution {
        public void rotate1(int[] nums, int k) {
            int n = nums.length;
            int[] newArr = new int[n];
            for (int i = 0; i < n; ++i) {
                newArr[(i + k) % n] = nums[i];
            }
            System.arraycopy(newArr, 0, nums, 0, n);
        }
    }

    public void rotate(int[] nums, int k) {
        k = k % nums.length;
        //依次翻转0-n,0-k,k-n
        conver(nums,0,nums.length - 1);
        conver(nums,0,k- 1 );
        conver(nums,k,nums.length - 1);

    }

    //翻转
    void conver(int[] nums,int left,int right) {
        while(left < right) {
            int tem = nums[right];
            nums[right] = nums[left];
            nums[left] = tem;
            right--;
            left++;
        }
    }
}
